
clear all

* Set the working directory
* Please change to your own working directory
cd "/Users/vicentevalentim/Desktop/PSRM Replication"

********************************************************************************
***************************** 1. PRE-PROCESSING ********************************
********************************************************************************

use Data/anes_timeseries_cdf_stata13.dta, clear

* Renaming variables to be used
* Variable indicating whether someone was contacted by a major party
fre VCF9030a
recode VCF9030a (1 = 1) (2 = 0) (8 9 = .), gen(contacted)

* Variable for election year
rename VCF0004 elecyear

* Variable for how long respondents have lived in the community
rename VCF9001 length_residence
replace length_residence = . if length_residence == 99

* Generate dummy for respondents who have moved
gen moved = 1
replace moved = 0 if length_residence == 90
replace moved = . if length_residence == 99

ta length_residence moved

* Controls 

rename VCF0101 age
replace age = . if age == 0
ta age

recode VCF0104 (2 = 1) (1 3 = 0) (0 = .), gen(female)
ta female VCF0104

rename VCF0105b race
replace race = . if race == 0 | race == 9
ta race

recode VCF0113 (1 = 1) (2 = 0), gen(south)
ta VCF0113 south

rename VCF0112 region
ta region

gen state_code = VCF0901a
replace state_code = . if state_code == 00
destring state_code, replace
ta state_code

* Attitudinal dependent variables

rename VCF0310 int_elec

replace int_elec = . if int_elec == 9 | int_elec == 0
ta int_elec


rename VCF0604 sup_trustgov
replace sup_trustgov = . if sup_trustgov == 0 | sup_trustgov == 9
ta sup_trustgov

recode VCF0609 (1 = 1) (2 = 0) (else = .), gen(sup_extefficacy)
ta VCF0609 sup_extefficacy

recode VCF0612 (1 = 1) (2 = 0) (0 9 = .), gen(sup_votesay)
ta VCF0612 sup_votesay

recode VCF0613 (1 = 1) (2 = 0) (else = .), gen(sup_intefficacy)
ta VCF0613 sup_intefficacy

recode VCF0614 (1 = 1) (2 = 0) (else = .), gen(sup_polcomplicated)
ta VCF0614 sup_polcomplicated

recode VCF0615 (1 = 1) (2 = 0) (else = .), gen(sup_votematters)
ta VCF0615 sup_votematters

rename VCF0648 extefficacy_index

rename VCF0649 govrespnsv_index

recode VCF0702 (1 = 0) (2 = 1) (0 = .), gen(voted)
ta voted VCF0702

rename VCF0723 campaignpart
replace campaignpart = . if campaignpart == 0


** Sociodemographics
ta VCF0110
recode VCF0110 (0 = .) (1/3 = 0) (4 = 1), gen(college)
ta VCF0110 college

gen edu =  VCF0110 
replace edu = . if edu == 0
ta VCF0110 edu

ta VCF0111
recode VCF0111 (0 = .) (1/2 = 0) (3 = 1), gen(rural)

gen urbanism =  VCF0111 
replace urbanism = . if urbanism == 0
ta VCF0111 urbanism

ta VCF0114
recode VCF0114 (0 = .) (1/3 = 0) (4 5 = 1), gen(highinc)

ta VCF0102
rename VCF0102 agegroup
replace agegroup = . if agegroup == 0
ta agegroup

ta VCF0450
recode VCF0450 (0 8 = .) (1 = 1) (2 = 0), gen(pres_approval)
ta pres_approval VCF0450

ta VCF0501
recode VCF0501 (0 9 = .) (1 = 0) (2 = 1), gen(party_difference)
ta party_difference VCF0501

ta VCF0611
recode VCF0611 (0 9 = .) (1 = 1) (2 = 0), gen(parties_only_int_votes)
ta parties_only_int_votes VCF0611

* Recode income to make it go in steps of 33
recode VCF0114 (0 = .) (1/2 = 1) (3 = 2) (4/5 = 3), gen(income)
ta VCF0114 income 

** Dropping data from 1948 and 1952 because turnout, age and age again, respectively, were not asked
ta elecyear
drop if elecyear <= 1954
 
** Keep only variables that matter to us
keep elecyear age female race south income urbanism edu agegroup ///
int_elec   VCF0114 highinc contacted ///
  sup_trustgov sup_extefficacy sup_votesay ///
sup_intefficacy sup_polcomplicated sup_votematters extefficacy_index ///
govrespnsv_index voted campaignpart region   college state_code ///
parties_only_int_votes party_difference pres_approval  moved length_residence  VCF0140

save anes_timeseries.dta, replace

******************************************************************
** Appending pilot study for midterm elections 2006 pilot study **
******************************************************************

use Data/anes2006pilot.dta, clear

* Renaming variables we may want to use

gen contacted = .

* Controls 
gen elecyear = 2006

ta V06P006
rename V06P006 age

fre V06P005
recode V06P005 (2 = 1) (1 = 0) (0 = .), gen(female)
ta female V06P005

fre V06P775x
recode V06P775x (1 = 1) (2 = 0), gen(voted)
ta V06P775x voted

gen south = .

ta V06P102
gen state_code = V06P102
tostring state_code, force replace
destring state_code, replace
ta state_code

* Attitudinal dependent variables
gen int_elec = .

fre V06P654
gen sup_trustgov = 5 - V06P654
replace sup_trustgov = . if sup_trustgov == -3 
ta sup_trustgov

gen sup_extefficacy = .

gen sup_votesay = .

recode V06P651 (4 5 = 1) (1 / 3 = 0) (8 = .), gen(sup_intefficacy)
ta V06P651 sup_intefficacy

gen sup_polcomplicated = .

gen sup_votematters = .

gen extefficacy_index = .

gen govrespnsv_index = .

gen campaignpart = . 

** Sociodemographics 
gen race = .

gen edu = .

gen college = .

gen urbanism = .

gen highinc = .


** Keep only variables that matter to us
keep elecyear age female race south urbanism edu  ///
 int_elec highinc contacted ///
 sup_trustgov sup_extefficacy sup_votesay ///
sup_intefficacy sup_polcomplicated sup_votematters extefficacy_index ///
govrespnsv_index voted campaignpart   college state_code

append using anes_timeseries

save anes_timeseriesplus2010, replace

******************************************************************
** Appending pilot study for midterm elections 2018 pilot study **
******************************************************************

use Data/anes_pilot_2018.dta, clear

* Renaming variables we may want to use
gen contacted = .

* Controls 
gen elecyear = 2018

ta birthyr
gen age = 2018 - birthyr
ta age

fre gender
recode gender (2 = 1) (1 = 0) (0 = .), gen(female)
ta female gender

fre turnout18
recode turnout18 (1/3 = 1) (4 = 0) (5 = .), gen(voted)
ta turnout18 voted

gen south = .

fre inputstate
gen state_code = inputstate
replace state_code = . if state_code < 0
ta state_code

* Attitudinal variables

gen int_elec = .

gen sup_trustgov = .

gen sup_extefficacy = .

gen sup_votesay = .

gen sup_intefficacy = .

gen sup_polcomplicated = .

gen sup_votematters = .

gen extefficacy_index = .

gen govrespnsv_index = .

gen campaignpart = . 

** Sociodemographics
rename race race2
fre race2
recode race2 (1 = 1) (2 = 2) (3 = 3) (4/7 = 4) (-7 = .), gen(race)
ta race 

gen edu = .

gen college = .

gen urbanism = .

gen highinc = .

** Keep only variables that matter to us
keep elecyear age female race south urbanism edu contacted ///
 int_elec highinc ///
 sup_trustgov sup_extefficacy sup_votesay ///
sup_intefficacy sup_polcomplicated sup_votematters extefficacy_index ///
govrespnsv_index voted campaignpart   college state_code

** Append
append using anes_timeseriesplus2010

** Generate variable for whether the election is presidential or midterm
ta elecyear
dis (2016-1948) / 4 /* We have 17 presidential elections in the dataset */
gen presidential = 0
forvalues x = 0/30{
				replace presidential = 1 if elecyear == 1900 + `x'*4
				}

ta elecyear presidential

/* Generate other necessary variables */

sum age 
				/* The oldest respondents are 99 years old */ 
ta elecyear if age == 99 
				/* The oldest of them is in the election of 1976 */
dis (1976-99) 
				/* She had been born in 1877, 
				meaning that she voted for the first time in the 1898 midterm election */

dis (2016-1898)/2 			
				/* There had been 59 elections between 1938 and 2016  */

dis 1972 - 18 
				/* Respondents aged 18 in 1972 (when voting age changed) 
				had been born in 1954 */
				
* Generating variable for date of birth
gen birthyr = elecyear - age
ta birthyr

* Generating variable that tells us the date each respondent was first eligible
gen firstel_date = .
replace firstel_date = birthyr + 21 if birthyr < 1952
replace firstel_date = birthyr + 18 if birthyr > 1952
replace firstel_date = 1972 if birthyr == 1952
ta firstel_date

* Generating dummy for women who came of age before 1920
gen wb20 = 0
replace wb20 = 1 if birthyr <= 1902 & female == 1

/* Generating variable that tells us for how many elections has 
respondent been eligible to vote (1 means first election she is eligible) */
gen elections = .

forvalues x = 0/70{
replace elections = `x'+1 if elecyear == firstel_date + `x'*2
replace elections = `x'+1 if elecyear == firstel_date + 1 + `x'*2
}
				/* Note: as I don't know what is the maximum number of elections
				any respondent lived through, I assume there
				was a maximum of 70. 
				Of course, this is an exaggeration, but this way we are sure
				not to have missed anything. */

ta elections

/* Generating variable that tells us for how many presidential elections has 
respondent been eligible to vote (1 means first pres election she is eligible) 

			To do this, I divide the variable elections by 2, and then round it up.*/

gen pres_count = elections / 2
replace pres_count = round(pres_count, 1)

		/* 	Then I replace it with missings in each midterm elections. */

replace pres_count = . if presidential == 0

		/* 	Checking if it seems ok: */

ta pres_count presidential, mis

* Now the same thing for midterm elections:
gen midterm_count = elections / 2
replace midterm_count = round(midterm_count, 1)

replace midterm_count = . if presidential == 1

ta midterm_count presidential, mis

/* Generating variable that tells us if first election for which respondent was
eligible was presidential */

gen first_pres = .

forvalues x = 0/40{
				replace first_pres = 1 if firstel_date == 1900 + `x'*4
				replace first_pres = 1 if firstel_date == 1899 + `x'*4
				}

forvalues x = 0/40{
				replace first_pres = 0 if firstel_date == 1898 + `x'*4
				replace first_pres = 0 if firstel_date == 1897 + `x'*4
				}
				
				/* Note: as not all elections are in this dataset, I assume there
				had been 40 midterm and 40 presidential elections since 1989. 
				Of course, this is an exaggeration, but this way we are sure
				not to have missed anything. */
				
ta first_pres
ta age if first_pres == ., mis

* Generating a placebo that is one year away from the treatment
gen placebo = .

forvalues x = 0/40{
				replace placebo = 1 if firstel_date == 1901 + `x'*4
				replace placebo = 1 if firstel_date == 1900 + `x'*4
				}

forvalues x = 0/40{
				replace placebo = 0 if firstel_date == 1899 + `x'*4
				replace placebo = 0 if firstel_date == 1898 + `x'*4
				}

* Standardizing attitudinal variables 

egen int_elec_m = mean(int_elec)
egen int_elec_sd = sd(int_elec)
gen int_elec_std = (int_elec - int_elec_m) / int_elec_sd
sum int_elec_std

egen sup_trustgov_m = mean(sup_trustgov)
egen sup_trustgov_sd = sd(sup_trustgov)
gen sup_trustgov_std = (sup_trustgov - sup_trustgov_m) / sup_trustgov_sd
sum sup_trustgov_std

egen sup_extefficacy_m = mean(sup_extefficacy)
egen sup_extefficacy_sd = sd(sup_extefficacy)
gen sup_extefficacy_std = (sup_extefficacy - sup_extefficacy_m) / sup_extefficacy_sd
sum sup_extefficacy_std

egen sup_votesay_m = mean(sup_votesay)
egen sup_votesay_sd = sd(sup_votesay)
gen sup_votesay_std = (sup_votesay - sup_votesay_m) / sup_votesay_sd
sum sup_votesay_std

egen sup_intefficacy_m = mean(sup_intefficacy)
egen sup_intefficacy_sd = sd(sup_intefficacy)
gen sup_intefficacy_std = (sup_intefficacy - sup_intefficacy_m) / sup_intefficacy_sd
sum sup_intefficacy_std

egen sup_polcomplicated_m = mean(sup_polcomplicated)
egen sup_polcomplicated_sd = sd(sup_polcomplicated)
gen sup_polcomplicated_std = (sup_polcomplicated - sup_polcomplicated_m) / sup_polcomplicated_sd
sum sup_polcomplicated_std

egen sup_votematters_m = mean(sup_votematters)
egen sup_votematters_sd = sd(sup_votematters)
gen sup_votematters_std = (sup_votematters - sup_votematters_m) / sup_votematters_sd
sum sup_votematters_std

egen extefficacy_index_m = mean(extefficacy_index)
egen extefficacy_index_sd = sd(extefficacy_index)
gen extefficacy_index_std = (extefficacy_index - extefficacy_index_m) / extefficacy_index_sd
sum extefficacy_index_std

egen govrespnsv_index_m = mean(govrespnsv_index)
egen govrespnsv_index_sd = sd(govrespnsv_index)
gen govrespnsv_index_std = (govrespnsv_index - govrespnsv_index_m) / govrespnsv_index_sd
sum govrespnsv_index_std

egen campaignpart_m = mean(campaignpart)
egen campaignpart_sd = sd(campaignpart)
gen campaignpart_std = (campaignpart - campaignpart_m) / campaignpart_sd
sum campaignpart_std

* Generate dummies for race variable
ta race, gen(race_d)

* Generate dummy for individuals in their first eligible year

gen first_eligible_in_odd_year = mod(firstel_date,2)
recode first_eligible_in_odd_year (1 = 0) (0 = 1), gen(eligible_in_even_year)

* Generate dummy for white respondents	
gen white=0
replace white = 1 if race == 1

* Generate variable for age squared
gen agesq = age^2

* Recode education 
gen educ2=0
replace educ2=1 if edu>1 
replace educ2=. if edu==.

** Saving new dataset
save Data/anes_cumulative, replace
drop if age == . | voted == . | elections == . | first_pres == .
export delimited using "~/Dropbox/Two habits formed hand-in-hand/Two habits formed in the shadow of the voting booth/Data/anes_cumulative.csv", replace

********************************************************************************
***************************** 2. MAIN ANALYSES *********************************
********************************************************************************

	use Data/anes_cumulative, clear



	* Entropy balance
	*ebalance first_pres age i.edu i.edu i.race i.college i.female, tar(3)
	*svyset [pweight=_webal]

	** Analyses for midterm elections
	* Generating variable for each midterm election
	ta midterm_count,gen(mid)
	ta pres_count,gen(presel)



	* Main analyses

	 
	tab edu,gen(ed)


	estimates clear

*********************
*Table 1 starts here*
*********************
*********************
*Table 1 starts here*
*********************

	estpost sum ed1 ed2 ed3 ed4 white age agesq south if first_pres==0
	matrix meanf0=e(mean)
	matrix list meanf0
	
	estpost sum ed1 ed2 ed3 ed4 white age agesq south if first_pres==1
	matrix meanf1=e(mean)
	matrix list meanf1
	 
	estpost ttest ed1 ed2 ed3 ed4 white age agesq south,by(first_pres)
	
	sum ed1 ed2 ed3 ed4 white age agesq south /*For columns 4 and 5 */

*********************
*Table 1 ends here*
*********************

*********************
*Table 2 starts here*
*********************

	
	ta region,gen(rg)
	ttest parties_only_int_votes,by(first_pres) 
	ttest pres_approval,by(first_pres) 
	ttest highinc,by(first_pres) 
	ttest moved,by(first_pres) 
	ttest urbanism,by(first_pres) 
	ttest rg1,by(first_pres) 
	ttest rg2,by(first_pres) 
	ttest rg3,by(first_pres) 
	ttest rg4,by(first_pres) 
	ttest sup_trustgov,by(first_pres) 
	ttest sup_extefficacy,by(first_pres) 
	ttest sup_votesay,by(first_pres) 
	ttest sup_intefficacy,by(first_pres) 
	ttest sup_polcomplicated,by(first_pres) 
	ttest sup_votematters,by(first_pres)
	ttest govrespnsv_index,by(first_pres) 



*******************
*Table 2 ends here*
*******************

*******************************
*Data for Figure 2 starts here*
*******************************

	

	capture erase ttest.txt
	foreach var of varlist highinc parties_only_int_votes pres_approval moved urbanism rg1 rg2 rg3 rg4 sup_trustgov sup_extefficacy sup_votesay sup_intefficacy sup_polcomplicated sup_votematters govrespnsv_index {
	ttest `var', by(first_pres)
	matrix ttest = (r(p))
	matrix rownames ttest = `var'
	matrix colnames ttest = "p-value"
	mat2txt, matrix(ttest) saving(ttest) append
	}

	capture postutil clear
	postfile handle str32 variable float (t_stat p_value) using ttest_results, replace

	foreach var of varlist highinc parties_only_int_votes pres_approval moved urbanism rg1 rg2 rg3 rg4 sup_trustgov sup_extefficacy sup_votesay sup_intefficacy sup_polcomplicated sup_votematters govrespnsv_index {
		ttest `var', by(first_pres)
		post handle ("`var'") (`r(t)') (`r(p)')
	}

	postclose handle


*****************************
*Data for Figure 2 ends here*
*****************************


		 


	gen count=.
	forvalues x=1/20 {
	replace count=`x' if midterm_count==`x' |  pres_count==`x'
	}

	ta count,gen(cn)


	forvalues x=1/20 {
	gen treatxall`x' = first_pres*cn`x' 
	}

	forvalues x=1/20 {
	gen all`x'pres = cn`x'*presidential 
	}

	gen treatxpres = first_pres*presidential 	

	forvalues x=1/20 {
	gen treatxall`x'pres = first_pres*cn`x'*presidential 
	}





	gen same=.
	replace same=1 if first_pres==1 & presidential==1
	replace same=1 if first_pres==0 & presidential==0
	replace same=0 if first_pres==1 & presidential==0
	replace same=0 if first_pres==0 & presidential==1

	forvalues x=1/20 {
	gen samecount`x'=same*cn`x'
	}

	gen samepres=same*presidential




	*############################################
	*##Results: Main entry of Figure 3, panel A##
	*############################################




	regr voted  same cn2-cn15 presidential ///
	age agesq i.edu i.female white  ///
	if count > 1 ,cluster(state_code)

	estimates store vote_eq1

	 
	  foreach num of numlist 90 95 {
	estimates store old
	lincomest same , level(`num') /* main (pooled) effect */
	parmest, label saving(Data/same`num'.dta, replace)   level(`num')
	estimates restore old
	}
	
	
*#################################################################
*##Results: Figure 3, panel A, Presidential and midterm entries###
*#################################################################


	regr voted  same cn2-cn15 presidential samepres ///
	age agesq i.edu i.female white  ///
	if count > 1 ,cluster(state_code)

	estimates store vote_eq2


	  foreach num of numlist 90 95 {
	estimates store old
	lincomest same , level(`num') /* Midterm effect */
	parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
	estimates restore old
	}

	  foreach num of numlist 90 95 {
	estimates store old
	lincomest same+samepres , level(`num') /* Presidential effect */
	parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
	estimates restore old
	}


*#######################################################
*##Results: Figure 3, panel B, Middle (pooled) entry ###
*#######################################################



	regr voted cn2-cn15 same presidential samecount2-samecount15 ///
	age agesq i.edu i.female white  ///
	if count > 1 ,cluster(state_code)

	estimates store vote_eq3


	 forvalues x=2/15{
	  foreach num of numlist 90 95 {
	estimates store old
	lincomest same + samecount`x' , level(`num') /*middle entry */
	parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
	estimates restore old
	}
	}

*#################################################################
*##Results: Figure 3, panel B, Presidential and midterm entries###
*#################################################################




	forvalues x=1/20 {
	gen count`x'pres=cn`x'*presidential
	}


	forvalues x=1/20 {
	gen samecount`x'pres=same*cn`x'*presidential
	}

	regr voted cn2-cn15 same presidential ///
	 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
	age agesq i.edu i.female white   ///
	if count > 1 ,cluster(state_code)

	estimates store vote_eq4

	
		

	***************************************
	*Table version: Table B1 in Appendix B*
	***************************************
	
	esttab vote_eq1 vote_eq2 vote_eq3 vote_eq4 using Latex/table_vote, replace tex ///
	coeflabels (same "Same" presidential "Presidential" ///
	samepres "Same x Pres. Election" /// 
	cn2 "2nd Election" cn3 "3rd Election" ///
	cn4 "4th Election" cn5 "5th Election" ///
	cn6 "6th Election" cn7 "7th Election" ///
	cn8 "8th Election" cn9 "9th Election" ///
	cn10 "10th Election" cn11 "9th Election" ///
	cn12 "12th Election" cn13 "13th Election" ///
	cn14 "14th Election" cn15 "15th Election" ///
	count2pres "Presidential x 2nd Election" count3pres "Presidential x 3rd Election" ///
	count4pres "Presidential x 4th Election" count5pres "Presidential x 5th Election" ///
	count6pres "Presidential x 6th Election" count7pres "Presidential x 7th Election" ///
	count8pres "Presidential x 8th Election" count9pres "Presidential x 9th Election" ///
	count10pres "Presidential x 10th Election" count11pres "Presidential x 11th Election" ///
	count12pres "Presidential x 12th Election" count13pres "Presidential x 13th Election" ///
	count14pres "Presidential x 14th Election" count15pres "Presidential x 15th Election" ///
	samecount2 "Same x 2nd Election" samecount3 "Same x 3rd Election" ///
	samecount4 "Same x 4th Election" samecount5 "Same x 5th Election" ///
	samecount6 "Same x 6th Election" samecount7 "Same x 7th Election" ///
	samecount8 "Same x 8th Election" samecount9 "Same x 9th Election" ///
	samecount10 "Same x 10th Election" samecount11 "Same x 11th Election" ///
	samecount12 "Same x 12th Election" samecount13 "Same x 13th Election" ///
	samecount14 "Same x 14th Election" samecount15 "Same x 15th Election" ///
	samecount2pres "Pres. x Same x 2nd Election" samecount3pres "Pres. x Same x 3rd Election" ///
	samecount4pres "Pres. x Same x 4th Election" samecount5pres "Pres. x Same x 5th Election" ///
	samecount6pres "Pres. x Same x 6th Election" samecount7pres "Pres. x Same x 7th Election" ///
	samecount8pres "Pres. x Same x 8th Election" samecount9pres "Pres. x Same x 9th Election" ///
	samecount10pres "Pres. x Same x 10th Election" samecount11pres "Pres. x Same x 11th Election" ///
	samecount12pres "Pres. x Same x 12th Election" samecount13pres "Pres. x Same x 13th Election" ///
	samecount14pres "Pres. x Same x 14th Election" samecount15pres "Pres. x Same x 15th Election" ///
	age "Age" agesq "Age squared" 2.edu "High school" ///
	3.edu "Some college" 4.edu "College or advance degree" 1.female "Dummy female" ///
	white "Dummy white" _cons "Constant") ///
	order (same presidential same samepres cn2 cn3 cn4 cn5 cn6 cn7 cn8 cn9 cn10 /// 
	cn11 cn12 cn13 cn14 cn15 count2pres count3pres count4pres count5pres count6pres ///
	count7pres count8pres count9pres count10pres count11pres count12pres count13pres ///
	count14pres count15pres samecount2 samecount3 samecount4 samecount5 samecount6 ///
	samecount7 samecount8 samecount9 samecount10 samecount11 samecount12 samecount13 ///
	samecount14 samecount15 samecount2pres samecount3pres samecount4pres samecount5pres ///
	samecount6pres samecount7pres samecount8pres samecount9pres samecount10pres ///
	samecount11pres samecount12pres samecount13pres samecount14pres samecount15pres ///
	age agesq 2.edu 3.edu 4.edu 1.female white _cons) ///
	nobaselevels  mtitles () star (* 0.1 ** 0.05 *** 0.01) se nomtitles longtable ///
	addnote("Standard errors are clustered by state") 


	 forvalues x=2/15{
	  foreach num of numlist 90 95 {
	estimates store old
	lincomest same + samecount`x' , level(`num') /* midterm entry */
	parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
	estimates restore old
	}
	}


	 forvalues x=2/15{
	  foreach num of numlist 90 95 {
	estimates store old
	lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num') /* presidential entry */
	parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
	estimates restore old
	}
	}


	
save for_interest, replace	
	
******************************************************
*Code to prepare dataset with estimates for the plots*
******************************************************

**************************************************
*Code for dataset for plot 3, Panel A starts here*
**************************************************	



	foreach num of numlist 90 95 {
	use Data/same`num'.dta, clear
	gen id=2
	save Data/same`num'n.dta, replace
	}

	foreach num of numlist 90 95 {
	use Data/samemid`num'.dta, clear
	gen id=3
	save Data/samemid`num'n.dta, replace
	}

	foreach num of numlist 90 95 {
	use Data/samepres`num'.dta, clear
	gen id=1
	save Data/samepres`num'n.dta, replace
	}



	use Data/same90n
	append using Data/samemid90n
	append using Data/samepres90n


	saveold Data/sameaverage90.dta, replace version(12)


	use Data/same95n
	append using Data/samemid95n
	append using Data/samepres95n


	saveold Data/sameaverage95.dta, replace version(12)


	

	use Data/sameaverage90, clear
	merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
	saveold Data/sameaveragecontrols.dta, replace version(12)

************************************************
*Code for dataset for plot 3, Panel A ends here*
************************************************	

**************************************************
*Code for dataset for plot 3, Panel B starts here*
**************************************************	
	
	


	forvalues x=2/15{
	foreach num of numlist 90 95 {
	use Data/same`x'`num'.dta, clear
	gen id=`x'
	save Data/same`x'`num'n.dta, replace
	}
	}


	use Data/same290n
	forvalues x=3/15{
	append using Data/same`x'90n
	}

	saveold Data/sameAll90.dta, replace version(12)

	use Data/same295n
	forvalues x=3/15{
	append using Data/same`x'95n
	}

	saveold Data/sameAll95.dta, replace version(12)



	use Data/sameAll90, clear
	merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
	gen id2=2
	gen id3=2
	saveold Data/sameAllcontrols.dta, replace version(12)






	forvalues x=2/15{
	foreach num of numlist 90 95 {
	use Data/same`x'`num'midterm.dta, clear
	gen id=`x'
	save Data/same`x'`num'midtermn.dta, replace
	}
	}


	use Data/same290midtermn
	forvalues x=3/15{
	append using Data/same`x'90midtermn
	}

	saveold Data/samemidterm90.dta, replace version(12)

	use Data/same295midtermn
	forvalues x=3/15{
	append using Data/same`x'95midtermn
	}

	saveold Data/samemidterm95.dta, replace version(12)



	use Data/samemidterm90, clear
	merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
	gen id2=2
	gen id3=3
	saveold Data/samemidtermcontrols.dta, replace version(12)







	forvalues x=2/15{
	foreach num of numlist 90 95 {
	use Data/same`x'`num'presi.dta, clear
	gen id=`x'
	save Data/same`x'`num'presin.dta, replace
	}
	}


	use Data/same290presin
	forvalues x=3/15{
	append using Data/same`x'90presin
	}

	saveold Data/samepresi90.dta, replace version(12)

	use Data/same295presin
	forvalues x=3/15{
	append using Data/same`x'95presin
	}

	saveold Data/samepresi95.dta, replace version(12)



	use Data/samepresi90, clear
	merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
	gen id2=2
	gen id3=1
	saveold Data/samepresicontrols.dta, replace version(12)



	use Data/sameAllcontrols
	append using Data/samemidtermcontrols
	append using Data/samepresicontrols

	saveold Data/samealltogether, replace version(12)



************************************************
*Code for dataset for plot 3, Panel B ends here*
************************************************
	
	
	use for_interest, clear
	
	
*############################################
*##Results: Main entry of Figure 4, panel A##
*############################################




regr int_elec  same cn2-cn15 presidential ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)
estimates store interest_eq1

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main (pooled) effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}




regr int_elec  same cn2-cn15 presidential samepres ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)

estimates store interest_eq2


  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Midterm effect */
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /* Presidential effect */
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*############################################
*##Results: Main entry of Figure 4, panel B##
*############################################




regr int_elec cn2-cn15 same presidential samecount2-samecount15 ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)
estimates store interest_eq3


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Midterm effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}





regr int_elec cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)

estimates store interest_eq4


***************************************
*Table version: Table B2 in Appendix B*
***************************************
	

esttab interest_eq1 interest_eq2 interest_eq3 interest_eq4 using Latex/table_interest, replace tex ///
coeflabels (same "Same" presidential "Presidential" ///
samepres "Same x Pres. Election" /// 
cn2 "2nd Election" cn3 "3rd Election" ///
cn4 "4th Election" cn5 "5th Election" ///
cn6 "6th Election" cn7 "7th Election" ///
cn8 "8th Election" cn9 "9th Election" ///
cn10 "10th Election" cn11 "9th Election" ///
cn12 "12th Election" cn13 "13th Election" ///
cn14 "14th Election" cn15 "15th Election" ///
count2pres "Presidential x 2nd Election" count3pres "Presidential x 3rd Election" ///
count4pres "Presidential x 4th Election" count5pres "Presidential x 5th Election" ///
count6pres "Presidential x 6th Election" count7pres "Presidential x 7th Election" ///
count8pres "Presidential x 8th Election" count9pres "Presidential x 9th Election" ///
count10pres "Presidential x 10th Election" count11pres "Presidential x 11th Election" ///
count12pres "Presidential x 12th Election" count13pres "Presidential x 13th Election" ///
count14pres "Presidential x 14th Election" count15pres "Presidential x 15th Election" ///
samecount2 "Same x 2nd Election" samecount3 "Same x 3rd Election" ///
samecount4 "Same x 4th Election" samecount5 "Same x 5th Election" ///
samecount6 "Same x 6th Election" samecount7 "Same x 7th Election" ///
samecount8 "Same x 8th Election" samecount9 "Same x 9th Election" ///
samecount10 "Same x 10th Election" samecount11 "Same x 11th Election" ///
samecount12 "Same x 12th Election" samecount13 "Same x 13th Election" ///
samecount14 "Same x 14th Election" samecount15 "Same x 15th Election" ///
samecount2pres "Pres. x Same x 2nd Election" samecount3pres "Pres. x Same x 3rd Election" ///
samecount4pres "Pres. x Same x 4th Election" samecount5pres "Pres. x Same x 5th Election" ///
samecount6pres "Pres. x Same x 6th Election" samecount7pres "Pres. x Same x 7th Election" ///
samecount8pres "Pres. x Same x 8th Election" samecount9pres "Pres. x Same x 9th Election" ///
samecount10pres "Pres. x Same x 10th Election" samecount11pres "Pres. x Same x 11th Election" ///
samecount12pres "Pres. x Same x 12th Election" samecount13pres "Pres. x Same x 13th Election" ///
samecount14pres "Pres. x Same x 14th Election" samecount15pres "Pres. x Same x 15th Election" ///
age "Age" agesq "Age squared" 2.edu "High school" ///
3.edu "Some college" 4.edu "College or advance degree" 1.female "Dummy female" ///
white "Dummy white" _cons "Constant") ///
order (same presidential same samepres cn2 cn3 cn4 cn5 cn6 cn7 cn8 cn9 cn10 /// 
cn11 cn12 cn13 cn14 cn15 count2pres count3pres count4pres count5pres count6pres ///
count7pres count8pres count9pres count10pres count11pres count12pres count13pres ///
count14pres count15pres samecount2 samecount3 samecount4 samecount5 samecount6 ///
samecount7 samecount8 samecount9 samecount10 samecount11 samecount12 samecount13 ///
samecount14 samecount15 samecount2pres samecount3pres samecount4pres samecount5pres ///
samecount6pres samecount7pres samecount8pres samecount9pres samecount10pres ///
samecount11pres samecount12pres samecount13pres samecount14pres samecount15pres ///
age agesq 2.edu 3.edu 4.edu 1.female white _cons) ///
nobaselevels  mtitles () star (* 0.1 ** 0.05 *** 0.01) se nomtitles longtable ///
addnote("Standard errors are clustered by state") 



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Midterm effect */
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num') /* Presidential effect */
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


**************************************************
*Code for dataset for plot 4, Panel A starts here*
**************************************************	




foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrolsInt.dta, replace version(12)


**************************************************
*Code for dataset for plot 4, Panel A ends here*
**************************************************	

**************************************************
*Code for dataset for plot 4, Panel B starts here*
**************************************************	


forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)






forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogetherInt, replace version(12)


**************************************************
*Code for dataset for plot 3, Panel B ends here*
**************************************************	


use for_interest, clear
	
	
*############################################
*##Results: Main entry of Figure C.1, panel A##
*############################################






regr contacted  same cn2-cn15 presidential ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main (pooled) effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}

*################################################################
*##Results: Left- and right-most entries of Figure C.1, panel A##
*################################################################




regr contacted  same cn2-cn15 presidential samepres ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /*Midterm effect*/
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /*Presidential effect*/
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*##############################################
*##Results: Main entry of Figure C.1, panel B##
*##############################################



regr contacted cn2-cn15 same samecount2-samecount15 ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num')  /*Main (pooled) effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}



regr contacted cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num')   /*Midterm effect */
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num') /* Presidential effect */
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


*######################################
*Code to prepare dataset for the plots*
*######################################

*########################################
*Code for Figure C1, Panel A starts here*
*########################################


foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=1
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=3
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrolsCon.dta, replace version(12)

*######################################
*Code for Figure C1, Panel A ends here*
*######################################

*########################################
*Code for Figure C1, Panel B starts here*
*########################################


forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)






forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogetherCon, replace version(12)


*######################################
*Code for Figure C1, Panel B ends here*
*######################################

*###################
*Code for Figure C2#
*###################



use for_interest, clear


drop same-samecount20pres 





gen same=.
replace same=1 if placebo==1 & presidential==1
replace same=1 if placebo==0 & presidential==0
replace same=0 if placebo==1 & presidential==0
replace same=0 if placebo==0 & presidential==1

forvalues x=1/20 {
gen samecount`x'=same*cn`x'
}

gen samepres=same*presidential


*###################*###############
*Middle entry of Panel A, Figure C2#
*###################*###############



regr voted  same cn2-cn15 presidential ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main (pooled) Effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}

*###################*#############################
*Left- and right-most entry of Panel A, Figure C2#
*###################*#############################



regr voted  same cn2-cn15 presidential samepres ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Midterm Effect */
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /* Presidential Effect */
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*###################*###############
*Middle entry of Panel B, Figure C2#
*###################*###############



regr voted cn2-cn15 same samecount2-samecount15 ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Main (pooled) Effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}

*###################*###############################
*Left- and Right-most entries of Panel B, Figure C2#
*###################*###############################




forvalues x=1/20 {
gen count`x'pres=cn`x'*presidential
}


forvalues x=1/20 {
gen samecount`x'pres=same*cn`x'*presidential
}



regr voted cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num')
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num')
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


*#################################
*#Preparing dataset for Figure C2#
*#################################


foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrolsPl.dta, replace version(12)



forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)






forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogetherPl, replace version(12)



*######################################
*Code for Figure C2, Panel B ends here*
*######################################













*###################
*Code for Figure C3#
*###################



use for_interest, clear


drop same-samecount20pres 





gen same=.
replace same=1 if placebo==1 & presidential==1
replace same=1 if placebo==0 & presidential==0
replace same=0 if placebo==1 & presidential==0
replace same=0 if placebo==0 & presidential==1

forvalues x=1/20 {
gen samecount`x'=same*cn`x'
}

gen samepres=same*presidential


*###################*###############
*Middle entry of Panel A, Figure C3#
*###################*###############



regr int_elec  same cn2-cn15 presidential ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main (pooled) Effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}

*###################*#############################
*Left- and right-most entry of Panel A, Figure C2#
*###################*#############################



regr int_elec  same cn2-cn15 presidential samepres ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Midterm Effect */
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /* Presidential Effect */
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*###################*###############
*Middle entry of Panel B, Figure C2#
*###################*###############



regr int_elec cn2-cn15 same samecount2-samecount15 ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Main (pooled) Effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}

*###################*###############################
*Left- and Right-most entries of Panel B, Figure C2#
*###################*###############################




forvalues x=1/20 {
gen count`x'pres=cn`x'*presidential
}


forvalues x=1/20 {
gen samecount`x'pres=same*cn`x'*presidential
}



regr int_elec cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num')
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num')
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}



*###########################################
*#Preparing dataset for the plot, Figure C3#
*###########################################

*###########################################
*#Preparing dataset for Panlel A, Figure C3#
*###########################################



foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrolsPlint.dta, replace version(12)


*###########################################
*#Dataset for Panlel A, Figure C3 ends here#
*###########################################

*#############################################
*#Dataset for Panlel B, Figure C3 starts here#
*#############################################


forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)






forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogetherPlint, replace version(12)





*###########################################
*#Dataset for Panlel B, Figure C3 ends here#
*###########################################


*####################
*#Code for Figure C4#
*####################

use for_interest, clear


*####################*#####################
*#Code for mid-entry of Panel A, Figure C4#
*####################*#####################



regr voted  same cn2-cn15 presidential ///
age agesq i.edu i.female white i.state_code ///
if count > 1 ,cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main Pooled Effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for left- and right-most entries of Panel A, Figure C4#
*#############################################################


regr voted  same cn2-cn15 presidential samepres ///
age agesq i.edu i.female white i.state_code ///
if count > 1 ,cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Midterm effect */
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /* Presidential effect */
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for mid-entries of Panel B, Figure C4#
*#############################################################



regr voted cn2-cn15 same samecount2-samecount15 ///
age agesq i.edu i.female white i.state_code ///
if count > 1 ,cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Main (pooled) effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}

*#############################################################
*#Code for left- and right-most entries of Panel B, Figure C4#
*#############################################################




regr voted cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu i.female white i.state_code ///
if count > 1 ,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Midterm effect */
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num') /* Presidential effect */
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


*#############################################
*#Code for preparation of datast for the plot#
*#############################################

*##############################
*#Code for Panel A starts here*
*##############################


foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrolsfe.dta, replace version(12)

*##############################
*#Code for Panel A ends here*
*##############################


*##############################
*#Code for Panel B starts here*
*##############################




forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)






forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogetherfe, replace version(12)











































*####################
*#Code for Figure C5#
*####################

use for_interest, clear


*####################*#####################
*#Code for mid-entry of Panel A, Figure C5#
*####################*#####################



regr int_elec  same cn2-cn15 presidential ///
age agesq i.edu i.female white i.state_code ///
if count > 1 ,cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main Pooled Effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for left- and right-most entries of Panel A, Figure C5#
*#############################################################


regr int_elec  same cn2-cn15 presidential samepres ///
age agesq i.edu i.female white i.state_code ///
if count > 1 ,cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Midterm effect */
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /* Presidential effect */
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for mid-entries of Panel B, Figure C5#
*#############################################################



regr int_elec cn2-cn15 same samecount2-samecount15 ///
age agesq i.edu i.female white i.state_code ///
if count > 1 ,cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Main (pooled) effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}

*#############################################################
*#Code for left- and right-most entries of Panel B, Figure C5#
*#############################################################




regr int_elec cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu i.female white i.state_code ///
if count > 1 ,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Midterm effect */
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num') /* Presidential effect */
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


*#############################################
*#Code for preparation of datast for the plot#
*#############################################

*##############################
*#Code for Panel A starts here*
*##############################



foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrolsfeint.dta, replace version(12)

*##############################
*#Code for Panel A ends here*
*##############################

*##############################
*#Code for Panel B starts here*
*##############################



forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)






forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogetherfeint, replace version(12)


*############################
*#Code for Panel B ends here*
*############################


























*####################
*#Code for Figure C6#
*####################

use for_interest, clear


*####################*#####################
*#Code for mid-entry of Panel A, Figure C6#
*####################*#####################



regr voted  same cn2-cn15 presidential ///
age agesq i.edu  ///
if count > 1 ,cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main Pooled Effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for left- and right-most entries of Panel A, Figure C6#
*#############################################################


regr voted  same cn2-cn15 presidential samepres ///
age agesq i.edu  ///
if count > 1 ,cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Midterm effect */
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /* Presidential effect */
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for mid-entries of Panel B, Figure C6#
*#############################################################



regr voted cn2-cn15 same samecount2-samecount15 ///
age agesq i.edu  ///
if count > 1 ,cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Main (pooled) effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}

*#############################################################
*#Code for left- and right-most entries of Panel B, Figure C6#
*#############################################################




regr voted cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu  ///
if count > 1 ,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Midterm effect */
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num') /* Presidential effect */
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


*#############################################
*#Code for preparation of datast for the plot#
*#############################################

*##############################
*#Code for Panel A starts here*
*##############################




foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrols_no.dta, replace version(12)



forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)


*##############################
*#Code for Panel A ends here*
*##############################

*##############################
*#Code for Panel B starts here*
*##############################





forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogether_no, replace version(12)

*############################
*#Code for Panel B ends here*
*############################























*####################
*#Code for Figure C7#
*####################

use for_interest, clear


*####################*#####################
*#Code for mid-entry of Panel A, Figure C7#
*####################*#####################



regr int_elec  same cn2-cn15 presidential ///
age agesq i.edu  ///
if count > 1 ,cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main Pooled Effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for left- and right-most entries of Panel A, Figure C7#
*#############################################################


regr int_elec  same cn2-cn15 presidential samepres ///
age agesq i.edu  ///
if count > 1 ,cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Midterm effect */
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /* Presidential effect */
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for mid-entries of Panel B, Figure C7#
*#############################################################



regr int_elec cn2-cn15 same samecount2-samecount15 ///
age agesq i.edu  ///
if count > 1 ,cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Main (pooled) effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}

*#############################################################
*#Code for left- and right-most entries of Panel B, Figure C7#
*#############################################################




regr int_elec cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu  ///
if count > 1 ,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Midterm effect */
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num') /* Presidential effect */
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


*#############################################
*#Code for preparation of datast for the plot#
*#############################################

*##############################
*#Code for Panel A starts here*
*##############################



foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrolsInt_no.dta, replace version(12)

*##############################
*#Code for Panel A ends here*
*##############################

*##############################
*#Code for Panel B starts here*
*##############################



forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)






forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogetherInt_no, replace version(12)



*##############################
*#Code for Panel B ends here*
*##############################

































*####################
*#Code for Figure C8#
*####################

use for_interest, clear

drop educ2
gen educ2=VCF0140
replace educ2=5 if VCF0140>3
replace educ2=. if VCF0140==.


*####################*#####################
*#Code for mid-entry of Panel A, Figure C8#
*####################*#####################



regr voted  same cn2-cn15 presidential ///
age agesq i.educ2 i.female white  ///
if count > 1 ,cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main Pooled Effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for left- and right-most entries of Panel A, Figure C8#
*#############################################################


regr voted  same cn2-cn15 presidential samepres ///
age agesq i.educ2 i.female white  ///
if count > 1 ,cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Midterm effect */
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /* Presidential effect */
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for mid-entries of Panel B, Figure C8#
*#############################################################



regr voted cn2-cn15 same presidential samecount2-samecount15 ///
age agesq i.educ2 i.female white  ///
if count > 1 ,cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Main (pooled) effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}

*#############################################################
*#Code for left- and right-most entries of Panel B, Figure C8#
*#############################################################




regr voted cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.educ2 i.female white  ///
if count > 1 ,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Midterm effect */
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num') /* Presidential effect */
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


*#############################################
*#Code for preparation of datast for the plot#
*#############################################

*##############################
*#Code for Panel A starts here*
*##############################



foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrols_educ2.dta, replace version(12)

*############################
*#Code for Panel A ends here*
*############################


*##############################
*#Code for Panel B starts here*
*##############################


forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)






forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogether_educ2, replace version(12)


*############################
*#Code for Panel B ends here*
*############################














*####################
*#Code for Figure C9#
*####################

use for_interest, clear

drop educ2
gen educ2=VCF0140
replace educ2=5 if VCF0140>3
replace educ2=. if VCF0140==.


*####################*#####################
*#Code for mid-entry of Panel A, Figure C9#
*####################*#####################



regr int_elec  same cn2-cn15 presidential ///
age agesq i.educ2 i.female white  ///
if count > 1 ,cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main Pooled Effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for left- and right-most entries of Panel A, Figure C9#
*#############################################################


regr int_elec  same cn2-cn15 presidential samepres ///
age agesq i.educ2 i.female white  ///
if count > 1 ,cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Midterm effect */
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /* Presidential effect */
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for mid-entries of Panel B, Figure C9#
*#############################################################



regr int_elec cn2-cn15 same presidential samecount2-samecount15 ///
age agesq i.educ2 i.female white  ///
if count > 1 ,cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Main (pooled) effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}

*#############################################################
*#Code for left- and right-most entries of Panel B, Figure C9#
*#############################################################




regr int_elec cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.educ2 i.female white  ///
if count > 1 ,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Midterm effect */
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num') /* Presidential effect */
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}

*#############################################
*#Code for preparation of datast for the plot#
*#############################################

*##############################
*#Code for Panel A starts here*
*##############################



foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrolsInt_educ2.dta, replace version(12)

*##############################
*#Code for Panel A ends here*
*##############################


*##############################
*#Code for Panel B starts here*
*##############################



forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)






forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogetherInt_educ2, replace version(12)


*##############################
*#Code for Panel B ends here*
*##############################














































*####################
*#Code for Figure C10#
*####################

use for_interest, clear

drop educ2
gen educ2=VCF0140
replace educ2=5 if VCF0140>3
replace educ2=. if VCF0140==.


*####################*#####################
*#Code for mid-entry of Panel A, Figure C10#
*####################*#####################



regr voted  same cn2-cn15 presidential ///
age agesq i.educ2  ///
if count > 1 ,cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main Pooled Effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for left- and right-most entries of Panel A, Figure C10#
*#############################################################


regr voted  same cn2-cn15 presidential samepres ///
age agesq i.educ2  ///
if count > 1 ,cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Midterm effect */
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /* Presidential effect */
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for mid-entries of Panel B, Figure C10#
*#############################################################



regr voted cn2-cn15 same presidential samecount2-samecount15 ///
age agesq i.educ2  ///
if count > 1 ,cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Main (pooled) effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}

*#############################################################
*#Code for left- and right-most entries of Panel B, Figure C10#
*#############################################################




regr voted cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.educ2  ///
if count > 1 ,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Midterm effect */
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num') /* Presidential effect */
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


*#############################################
*#Code for preparation of datast for the plot#
*#############################################

*##############################
*#Code for Panel A starts here*
*##############################




foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrols_no_educ2.dta, replace version(12)


*##############################
*#Code for Panel A ends here*
*##############################

*##############################
*#Code for Panel B starts here*
*##############################



forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogether_no_educ2, replace version(12)

*############################
*#Code for Panel B ends here*
*############################




















































*####################
*#Code for Figure C11#
*####################

use for_interest, clear

drop educ2
gen educ2=VCF0140
replace educ2=5 if VCF0140>3
replace educ2=. if VCF0140==.


*####################*#####################
*#Code for mid-entry of Panel A, Figure C11#
*####################*#####################



regr int_elec  same cn2-cn15 presidential ///
age agesq i.educ2  ///
if count > 1 ,cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main Pooled Effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for left- and right-most entries of Panel A, Figure C11#
*#############################################################


regr int_elec  same cn2-cn15 presidential samepres ///
age agesq i.educ2  ///
if count > 1 ,cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Midterm effect */
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /* Presidential effect */
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for mid-entries of Panel B, Figure C11#
*#############################################################



regr int_elec cn2-cn15 same presidential samecount2-samecount15 ///
age agesq i.educ2  ///
if count > 1 ,cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Main (pooled) effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}

*#############################################################
*#Code for left- and right-most entries of Panel B, Figure C11#
*#############################################################




regr int_elec cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.educ2  ///
if count > 1 ,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Midterm effect */
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num') /* Presidential effect */
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


*#############################################
*#Code for preparation of datast for the plot#
*#############################################

*##############################
*#Code for Panel A starts here*
*##############################




foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrolsInt_no_educ2.dta, replace version(12)


*##############################
*#Code for Panel A ends here*
*##############################

*##############################
*#Code for Panel B starts here*
*##############################



forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogetherInt_no_educ2, replace version(12)

*############################
*#Code for Panel B ends here*
*############################









































*####################
*#Code for Figure C12#
*####################

use for_interest, clear


*####################*#####################
*#Code for mid-entry of Panel A, Figure C12#
*####################*#####################



regr voted  same cn2-cn15 presidential ///
age agesq i.edu i.female white  i.region urbanism i.highinc ///
if count > 1 ,cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main Pooled Effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for left- and right-most entries of Panel A, Figure C12#
*#############################################################


regr voted  same cn2-cn15 presidential samepres ///
age agesq i.edu i.female white  i.region urbanism i.highinc ///
if count > 1 ,cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Midterm effect */
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /* Presidential effect */
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for mid-entries of Panel B, Figure C12#
*#############################################################



regr voted cn2-cn15 same presidential samecount2-samecount15 ///
age agesq i.edu i.female white  i.region urbanism i.highinc ///
if count > 1 ,cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Main (pooled) effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}

*#############################################################
*#Code for left- and right-most entries of Panel B, Figure C12#
*#############################################################




regr voted cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu i.female white  i.region urbanism i.highinc ///
if count > 1 ,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Midterm effect */
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num') /* Presidential effect */
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


*#############################################
*#Code for preparation of datast for the plot#
*#############################################

*##############################
*#Code for Panel A starts here*
*##############################




foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrols_full.dta, replace version(12)


*##############################
*#Code for Panel A ends here*
*##############################

*##############################
*#Code for Panel B starts here*
*##############################



forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogether_full, replace version(12)

*############################
*#Code for Panel B ends here*
*############################

















































*####################
*#Code for Figure C13#
*####################

use for_interest, clear


*####################*#####################
*#Code for mid-entry of Panel A, Figure C13#
*####################*#####################



regr int_elec  same cn2-cn15 presidential ///
age agesq i.edu i.female white  i.region urbanism i.highinc ///
if count > 1 ,cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Main Pooled Effect */
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for left- and right-most entries of Panel A, Figure C13#
*#############################################################


regr int_elec  same cn2-cn15 presidential samepres ///
age agesq i.edu i.female white  i.region urbanism i.highinc ///
if count > 1 ,cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num') /* Midterm effect */
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num') /* Presidential effect */
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}


*#############################################################
*#Code for mid-entries of Panel B, Figure C13#
*#############################################################



regr int_elec cn2-cn15 same presidential samecount2-samecount15 ///
age agesq i.edu i.female white  i.region urbanism i.highinc ///
if count > 1 ,cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Main (pooled) effect */
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}

*#############################################################
*#Code for left- and right-most entries of Panel B, Figure C13#
*#############################################################




regr int_elec cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu i.female white  i.region urbanism i.highinc ///
if count > 1 ,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num') /* Midterm effect */
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num') /* Presidential effect */
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


*#############################################
*#Code for preparation of datast for the plot#
*#############################################

*##############################
*#Code for Panel A starts here*
*##############################




foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrolsInt_full.dta, replace version(12)


*##############################
*#Code for Panel A ends here*
*##############################

*##############################
*#Code for Panel B starts here*
*##############################



forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogetherInt_full, replace version(12)

*############################
*#Code for Panel B ends here*
*############################









*####################
*#Code for Figure C14#
*####################

use for_interest, clear


*####################*#####################
*#Code for mid-entry of Panel A, Figure C14#
*####################*#####################






regr voted  same cn2-cn15 presidential  ///
age agesq i.edu female white  ///
if count > 1 & eligible_in_even_year==0 ,cluster(state_code)


estimates store vote_eq1

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num')
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}

*####################*#########################################
*#Code for left- and right-most entries of Panel A, Figure C14#
*####################*#########################################


regr voted  same cn2-cn15 presidential samepres ///
age agesq  i.female white i.edu ///
if count > 1 & eligible_in_even_year==0,cluster(state_code)

estimates store vote_eq2


  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num')
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num')
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}

*####################*#########################################
*#Code for midterm entry of Panel B, Figure C14#
*####################*#########################################



regr voted cn2-cn15 same samecount2-samecount15 presidential ///
age agesq i.female white i.edu ///
if count > 1 & eligible_in_even_year==0,cluster(state_code)

estimates store vote_eq3


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num')
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}


*####################*#########################################
*#Code for left- and right-most entries of Panel B, Figure C14#
*####################*#########################################



regr voted cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
 age agesq  i.female white i.edu ///
if count > 1 & eligible_in_even_year==0,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num')
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num')
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


*############################
*#Code for preparing the plot*
*############################

*############################
*#Code for Panel A starts here*
*############################



foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrols_no_odd.dta, replace version(12)


*############################
*#Code for Panel A ends here*
*############################

*############################
*#Code for Panel B starts here*
*############################




forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)






forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogether_no_odd, replace version(12)


*############################
*#Code for Panel B ends here*
*############################




















*####################
*#Code for Figure C15#
*####################

use for_interest, clear


*####################*#####################
*#Code for mid-entry of Panel A, Figure C15#
*####################*#####################






regr int_elec  same cn2-cn15 presidential  ///
age agesq i.edu female white  ///
if count > 1 & eligible_in_even_year==0 ,cluster(state_code)


estimates store vote_eq1

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num')
parmest, label saving(Data/same`num'.dta, replace)   level(`num')
estimates restore old
}

*####################*#########################################
*#Code for left- and right-most entries of Panel A, Figure C15#
*####################*#########################################


regr int_elec  same cn2-cn15 presidential samepres ///
age agesq  i.female white i.edu ///
if count > 1 & eligible_in_even_year==0,cluster(state_code)

estimates store vote_eq2


  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num')
parmest, label saving(Data/samemid`num'.dta, replace)   level(`num')
estimates restore old
}

  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num')
parmest, label saving(Data/samepres`num'.dta, replace)   level(`num')
estimates restore old
}

*####################*#########################################
*#Code for midterm entry of Panel B, Figure C15#
*####################*#########################################



regr int_elec cn2-cn15 same samecount2-samecount15 presidential ///
age agesq i.female white i.edu ///
if count > 1 & eligible_in_even_year==0,cluster(state_code)

estimates store vote_eq3


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num')
parmest, label saving(Data/same`x'`num'.dta, replace)   level(`num')
estimates restore old
}
}


*####################*#########################################
*#Code for left- and right-most entries of Panel B, Figure C15#
*####################*#########################################



regr int_elec cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
 age agesq  i.female white i.edu ///
if count > 1 & eligible_in_even_year==0,cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num')
parmest, label saving(Data/same`x'`num'midterm.dta, replace)   level(`num')
estimates restore old
}
}


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num')
parmest, label saving(Data/same`x'`num'presi.dta, replace)   level(`num')
estimates restore old
}
}


*############################
*#Code for preparing the plot*
*############################

*############################
*#Code for Panel A starts here*
*############################



foreach num of numlist 90 95 {
use Data/same`num'.dta, clear
gen id=2
save Data/same`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samemid`num'.dta, clear
gen id=3
save Data/samemid`num'n.dta, replace
}

foreach num of numlist 90 95 {
use Data/samepres`num'.dta, clear
gen id=1
save Data/samepres`num'n.dta, replace
}



use Data/same90n
append using Data/samemid90n
append using Data/samepres90n


saveold Data/sameaverage90.dta, replace version(12)


use Data/same95n
append using Data/samemid95n
append using Data/samepres95n


saveold Data/sameaverage95.dta, replace version(12)



use Data/sameaverage90, clear
merge  1:1 id using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrolsInt_no_odd.dta, replace version(12)


*############################
*#Code for Panel A ends here*
*############################

*############################
*#Code for Panel B starts here*
*############################




forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'.dta, clear
gen id=`x'
save Data/same`x'`num'n.dta, replace
}
}


use Data/same290n
forvalues x=3/15{
append using Data/same`x'90n
}

saveold Data/sameAll90.dta, replace version(12)

use Data/same295n
forvalues x=3/15{
append using Data/same`x'95n
}

saveold Data/sameAll95.dta, replace version(12)



use Data/sameAll90, clear
merge  1:1 id using  Data/sameAll95,keepusing(min95 max95)
gen id2=2
gen id3=2
saveold Data/sameAllcontrols.dta, replace version(12)






forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'midterm.dta, clear
gen id=`x'
save Data/same`x'`num'midtermn.dta, replace
}
}


use Data/same290midtermn
forvalues x=3/15{
append using Data/same`x'90midtermn
}

saveold Data/samemidterm90.dta, replace version(12)

use Data/same295midtermn
forvalues x=3/15{
append using Data/same`x'95midtermn
}

saveold Data/samemidterm95.dta, replace version(12)



use Data/samemidterm90, clear
merge  1:1 id using  Data/samemidterm95,keepusing(min95 max95)
gen id2=2
gen id3=3
saveold Data/samemidtermcontrols.dta, replace version(12)







forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'presi.dta, clear
gen id=`x'
save Data/same`x'`num'presin.dta, replace
}
}


use Data/same290presin
forvalues x=3/15{
append using Data/same`x'90presin
}

saveold Data/samepresi90.dta, replace version(12)

use Data/same295presin
forvalues x=3/15{
append using Data/same`x'95presin
}

saveold Data/samepresi95.dta, replace version(12)



use Data/samepresi90, clear
merge  1:1 id using  Data/samepresi95,keepusing(min95 max95)
gen id2=2
gen id3=1
saveold Data/samepresicontrols.dta, replace version(12)



use Data/sameAllcontrols
append using Data/samemidtermcontrols
append using Data/samepresicontrols

saveold Data/samealltogetherInt_no_odd, replace version(12)


*############################
*#Code for Panel B ends here*
*############################


********************************************************************************
*************************** 3. ONE ELECTION OUT ********************************
********************************************************************************

use Data/anes_cumulative, clear


* Generating variable for each midterm election
ta midterm_count,gen(mid)
ta pres_count,gen(presel)


	

* Main analyses

 
tab edu,gen(ed)


estimates clear


 
gen count=.
forvalues x=1/20 {
replace count=`x' if midterm_count==`x' |  pres_count==`x'
}

ta count,gen(cn)



gen same=.
replace same=1 if first_pres==1 & presidential==1
replace same=1 if first_pres==0 & presidential==0
replace same=0 if first_pres==1 & presidential==0
replace same=0 if first_pres==0 & presidential==1

forvalues x=1/20 {
gen samecount`x'=same*cn`x'
}

gen samepres=same*presidential




foreach year of numlist 1956(4)2016  {
regr voted  same cn2-cn15 presidential ///
age agesq i.edu i.female white  ///
if count > 1 & elecyear!=`year',cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num')
parmest, label saving(Data/same`num'`year'.dta, replace)   level(`num')
estimates restore old
}
}


foreach year of numlist 1956(4)2016  {
regr voted  same cn2-cn15 presidential samepres ///
age agesq i.edu i.female white  ///
if count > 1 & elecyear!=`year',cluster(state_code)





  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num')
parmest, label saving(Data/same`num'`year'presi.dta, replace)   level(`num')
estimates restore old
}
}

foreach year of numlist 1958(4)2006 2018 {
regr voted  same cn2-cn15 presidential samepres ///
age agesq i.edu i.female white  ///
if count > 1 & elecyear!=`year',cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num')
parmest, label saving(Data/same`num'`year'midterm.dta, replace)   level(`num')
estimates restore old
}
}




#############################
#over time for both together#
#############################


foreach year of numlist 1956(4)2016  {
regr voted cn2-cn15 same samecount2-samecount15 ///
age agesq i.edu i.female white  ///
if count > 1 & elecyear!=`year',cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num')
parmest, label saving(Data/same`x'`num'`year'.dta, replace)   level(`num')
estimates restore old
}
}
}



forvalues x=1/20 {
gen count`x'pres=cn`x'*presidential
}


forvalues x=1/20 {
gen samecount`x'pres=same*cn`x'*presidential
}

foreach year of numlist 1956(4)2016  {
regr voted cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu i.female white  ///
if count > 1 & elecyear!=`year',cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num')
parmest, label saving(Data/same`x'`num'`year'presi.dta, replace)   level(`num')
estimates restore old
}
}
}


foreach year of numlist 1958(4)2006 2018 {
regr voted cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu i.female white  ///
if count > 1 & elecyear!=`year',cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x', level(`num')
parmest, label saving(Data/same`x'`num'`year'midterm.dta, replace)   level(`num')
estimates restore old
}
}
}




#########
#Average#
#########





####################
#Same, all together#
####################


foreach year of numlist 1956(4)2016  {
foreach num of numlist 90 95 {
use Data/same`num'`year'.dta, clear
gen id1=`year'
gen id2=2
save Data/same`num'`year'n.dta, replace
}
}

###############
#Same, midterm#
###############


foreach year of numlist 1958(4)2006 2018 {
foreach num of numlist 90 95 {
use Data/same`num'`year'midterm.dta, clear
gen id1=`year'
gen id2=3
save Data/same`num'`year'midtermn.dta, replace
}
}

###############
#Same, preside#
###############


foreach year of numlist 1956(4)2016  {
foreach num of numlist 90 95 {
use Data/same`num'`year'presi.dta, clear
gen id1=`year'
gen id2=1
save Data/same`num'`year'presin.dta, replace
}
}

###############
#append 90#
###############


use Data/same901956n.dta
foreach year of numlist 1956(4)2016  {
append using Data/same90`year'n
append using Data/same90`year'presin
}
foreach year of numlist 1958(4)2006 2018 {
append using Data/same90`year'midtermn
}
gen id3=_n-1
drop if id3==0

saveold Data/sameaverage90.dta, replace version(12)

###############
#append 95#
###############


use Data/same951956n,clear
foreach year of numlist 1956(4)2016  {
append using Data/same95`year'n
append using Data/same95`year'presin
}
foreach year of numlist 1958(4)2006 2018 {
append using Data/same95`year'midtermn
}
gen id3=_n-1
drop if id3==0


saveold Data/sameaverage95.dta, replace version(12)


########
#merge#
#######



use Data/sameaverage90, clear
merge  1:1 id3 using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrolsoneout.dta, replace version(12)



###########
#Over time#
###########


###############
#same together#
###############




foreach year of numlist 1956(4)2016  {
forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'`year'.dta, clear
gen id1=`year'
gen id2=2
gen id3=`x'
save Data/same`x'`num'`year'n.dta, replace
}
}
}



use Data/same2901956n
foreach year of numlist 1956(4)2016  {
forvalues x=2/15{
append using Data/same`x'90`year'n
}
}

gen id4=_n-1
drop if id4==0

saveold Data/sameAll90.dta, replace version(12)



use Data/same2951956n
foreach year of numlist 1956(4)2016  {
forvalues x=2/15{
append using Data/same`x'95`year'n
}
}

gen id4=_n-1
drop if id4==0

saveold Data/sameAll95.dta, replace version(12)


use Data/sameAll90, clear
merge  1:1 id4 using  Data/sameAll95,keepusing(min95 max95)
gen id5=2
gen id6=2
saveold Data/sameAllcontrols.dta, replace version(12)





###############
#same midterm#
###############



foreach year of numlist 1958(4)2006 2018 {
forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'`year'midterm.dta, clear
gen id1=`year'
gen id2=3
gen id3=`x'
save Data/same`x'`num'`year'midtermn.dta, replace
}
}
}


** the problem is here (below); stata can't find this dataset. I think it should have been created by the chunk exactly above? Is the problem that the loop above starts in 1958, not in 1956?
use Data/same2901958midtermn.dta
foreach year of numlist 1958(4)2006 2018 {
forvalues x=2/15{
append using Data/same`x'90`year'midtermn
}
}

gen id4=_n-1
drop if id4==0

saveold Data/sameAll90midterm.dta, replace version(12)



use Data/same2951958midtermn
foreach year of numlist 1958(4)2006 2018 {
forvalues x=2/15{
append using Data/same`x'95`year'midtermn
}
}

gen id4=_n-1
drop if id4==0

saveold Data/sameAll95midterm.dta, replace version(12)


use Data/sameAll90midterm, clear
merge  1:1 id4 using  Data/sameAll95midterm,keepusing(min95 max95)
gen id5=2
gen id6=3
saveold Data/sameAllcontrolsmidterm.dta, replace version(12)






###############
#same preside#
###############



foreach year of numlist 1956(4)2016  {
forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'`year'presi.dta, clear
gen id1=`year'
gen id2=1
gen id3=`x'
save Data/same`x'`num'`year'presin.dta, replace
}
}
}



use Data/same2901956presin
foreach year of numlist 1956(4)2016  {
forvalues x=2/15{
append using Data/same`x'90`year'presin
}
}

gen id4=_n-1
drop if id4==0

saveold Data/sameAll90presi.dta, replace version(12)



use Data/same2951956presin
foreach year of numlist 1956(4)2016  {
forvalues x=2/15{
append using Data/same`x'95`year'presin
}
}

gen id4=_n-1
drop if id4==0

saveold Data/sameAll95presi.dta, replace version(12)


use Data/sameAll90presi, clear
merge  1:1 id4 using  Data/sameAll95presi,keepusing(min95 max95)
gen id5=2
gen id6=1
saveold Data/sameAllcontrolspresi.dta, replace version(12)




use Data/sameAllcontrols
append using Data/sameAllcontrolsmidterm
append using Data/sameAllcontrolspresi

saveold Data/samealltogether15oneout, replace version(12)


use Data/anes_cumulative, clear


* Generating variable for each midterm election
ta midterm_count,gen(mid)
ta pres_count,gen(presel)



* Main analyses

 
tab edu,gen(ed)


estimates clear


 
gen count=.
forvalues x=1/20 {
replace count=`x' if midterm_count==`x' |  pres_count==`x'
}

ta count,gen(cn)



gen same=.
replace same=1 if first_pres==1 & presidential==1
replace same=1 if first_pres==0 & presidential==0
replace same=0 if first_pres==1 & presidential==0
replace same=0 if first_pres==0 & presidential==1

forvalues x=1/20 {
gen samecount`x'=same*cn`x'
}

gen samepres=same*presidential

regr int_elec  same  ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)

regr int_elec  same  presidential ///
age agesq i.edu i.female white  ///
if count > 1 ,cluster(state_code)


foreach year of numlist 1956(4)2016  {
regr int_elec  same cn2-cn15 presidential ///
age agesq i.edu i.female white  ///
if count > 1 & elecyear!=`year',cluster(state_code)

 
  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num')
parmest, label saving(Data/same`num'`year'.dta, replace)   level(`num')
estimates restore old
}
}


foreach year of numlist 1956(4)2016  {
regr int_elec  same cn2-cn15 presidential samepres ///
age agesq i.edu i.female white  ///
if count > 1 & elecyear!=`year',cluster(state_code)





  foreach num of numlist 90 95 {
estimates store old
lincomest same+samepres , level(`num')
parmest, label saving(Data/same`num'`year'presi.dta, replace)   level(`num')
estimates restore old
}
}

foreach year of numlist 1958(4)2006 2018 {
regr int_elec  same cn2-cn15 presidential samepres ///
age agesq i.edu i.female white  ///
if count > 1 & elecyear!=`year',cluster(state_code)



  foreach num of numlist 90 95 {
estimates store old
lincomest same , level(`num')
parmest, label saving(Data/same`num'`year'midterm.dta, replace)   level(`num')
estimates restore old
}
}




#############################
#over time for both together#
#############################


foreach year of numlist 1956(4)2016  {
regr int_elec cn2-cn15 same samecount2-samecount15 ///
age agesq i.edu i.female white  ///
if count > 1 & elecyear!=`year',cluster(state_code)


 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' , level(`num')
parmest, label saving(Data/same`x'`num'`year'.dta, replace)   level(`num')
estimates restore old
}
}
}



forvalues x=1/20 {
gen count`x'pres=cn`x'*presidential
}


forvalues x=1/20 {
gen samecount`x'pres=same*cn`x'*presidential
}

foreach year of numlist 1956(4)2016  {
regr int_elec cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu i.female white  ///
if count > 1 & elecyear!=`year',cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x' + samepres + samecount`x'pres, level(`num')
parmest, label saving(Data/same`x'`num'`year'presi.dta, replace)   level(`num')
estimates restore old
}
}
}


foreach year of numlist 1958(4)2006 2018 {
regr int_elec cn2-cn15 same presidential ///
 count2pres-count15pres samecount2-samecount15 samepres samecount2pres-samecount15pres ///
age agesq i.edu i.female white  ///
if count > 1 & elecyear!=`year',cluster(state_code)



 forvalues x=2/15{
  foreach num of numlist 90 95 {
estimates store old
lincomest same + samecount`x', level(`num')
parmest, label saving(Data/same`x'`num'`year'midterm.dta, replace)   level(`num')
estimates restore old
}
}
}




#########
#Average#
#########





####################
#Same, all together#
####################


foreach year of numlist 1956(4)2016  {
foreach num of numlist 90 95 {
use Data/same`num'`year'.dta, clear
gen id1=`year'
gen id2=2
save Data/same`num'`year'n.dta, replace
}
}

###############
#Same, midterm#
###############


foreach year of numlist 1958(4)2006 2018 {
foreach num of numlist 90 95 {
use Data/same`num'`year'midterm.dta, clear
gen id1=`year'
gen id2=3
save Data/same`num'`year'midtermn.dta, replace
}
}

###############
#Same, preside#
###############


foreach year of numlist 1956(4)2016  {
foreach num of numlist 90 95 {
use Data/same`num'`year'presi.dta, clear
gen id1=`year'
gen id2=1
save Data/same`num'`year'presin.dta, replace
}
}

###############
#append 90#
###############


use Data/same901956n.dta
foreach year of numlist 1956(4)2016  {
append using Data/same90`year'n
append using Data/same90`year'presin
}
foreach year of numlist 1958(4)2006 2018 {
append using Data/same90`year'midtermn
}
gen id3=_n-1
drop if id3==0

saveold Data/sameaverage90.dta, replace version(12)

###############
#append 95#
###############


use Data/same951956n,clear
foreach year of numlist 1956(4)2016  {
append using Data/same95`year'n
append using Data/same95`year'presin
}
foreach year of numlist 1958(4)2006 2018 {
append using Data/same95`year'midtermn
}
gen id3=_n-1
drop if id3==0


saveold Data/sameaverage95.dta, replace version(12)


########
#merge#
#######



use Data/sameaverage90, clear
merge  1:1 id3 using  Data/sameaverage95,keepusing(min95 max95)
saveold Data/sameaveragecontrolsoneoutInt.dta, replace version(12)



###########
#Over time#
###########


###############
#same together#
###############




foreach year of numlist 1956(4)2016  {
forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'`year'.dta, clear
gen id1=`year'
gen id2=2
gen id3=`x'
save Data/same`x'`num'`year'n.dta, replace
}
}
}



use Data/same2901956n
foreach year of numlist 1956(4)2016  {
forvalues x=2/15{
append using Data/same`x'90`year'n
}
}

gen id4=_n-1
drop if id4==0

saveold Data/sameAll90.dta, replace version(12)



use Data/same2951956n
foreach year of numlist 1956(4)2016  {
forvalues x=2/15{
append using Data/same`x'95`year'n
}
}

gen id4=_n-1
drop if id4==0

saveold Data/sameAll95.dta, replace version(12)


use Data/sameAll90, clear
merge  1:1 id4 using  Data/sameAll95,keepusing(min95 max95)
gen id5=2
gen id6=2
saveold Data/sameAllcontrols.dta, replace version(12)





###############
#same midterm#
###############



foreach year of numlist 1958(4)2006 2018 {
forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'`year'midterm.dta, clear
gen id1=`year'
gen id2=3
gen id3=`x'
save Data/same`x'`num'`year'midtermn.dta, replace
}
}
}



use Data/same2901958midtermn
foreach year of numlist 1958(4)2006 2018 {
forvalues x=2/15{
append using Data/same`x'90`year'midtermn
}
}

gen id4=_n-1
drop if id4==0

saveold Data/sameAll90midterm.dta, replace version(12)



use Data/same2951958midtermn
foreach year of numlist 1958(4)2006 2018 {
forvalues x=2/15{
append using Data/same`x'95`year'midtermn
}
}

gen id4=_n-1
drop if id4==0

saveold Data/sameAll95midterm.dta, replace version(12)


use Data/sameAll90midterm, clear
merge  1:1 id4 using  Data/sameAll95midterm,keepusing(min95 max95)
gen id5=2
gen id6=3
saveold Data/sameAllcontrolsmidterm.dta, replace version(12)






###############
#same preside#
###############



foreach year of numlist 1956(4)2016  {
forvalues x=2/15{
foreach num of numlist 90 95 {
use Data/same`x'`num'`year'presi.dta, clear
gen id1=`year'
gen id2=1
gen id3=`x'
save Data/same`x'`num'`year'presin.dta, replace
}
}
}



use Data/same2901956presin
foreach year of numlist 1956(4)2016  {
forvalues x=2/15{
append using Data/same`x'90`year'presin
}
}

gen id4=_n-1
drop if id4==0

saveold Data/sameAll90presi.dta, replace version(12)



use Data/same2951956presin
foreach year of numlist 1956(4)2016  {
forvalues x=2/15{
append using Data/same`x'95`year'presin
}
}

gen id4=_n-1
drop if id4==0

saveold Data/sameAll95presi.dta, replace version(12)


use Data/sameAll90presi, clear
merge  1:1 id4 using  Data/sameAll95presi,keepusing(min95 max95)
gen id5=2
gen id6=1
saveold Data/sameAllcontrolspresi.dta, replace version(12)




use Data/sameAllcontrols
append using Data/sameAllcontrolsmidterm
append using Data/sameAllcontrolspresi

saveold Data/samealltogether15oneoutInt, replace version(12)


********************************************************************************
************************** 4. POLICY IMPLICATIONS ******************************
********************************************************************************


use Data/anes_cumulative.dta, clear

***********************
** Code for Table 3 ***
***********************

** You are suddenly eligible in a mid-term

gen year_of_birth=elecyear-age
 
keep if year_of_birth==1974-19 | year_of_birth==1974-20 ///
| year_of_birth==1978-19 | year_of_birth==1978-20 ///
| year_of_birth==1982-19  | year_of_birth==1982-20 ///
| year_of_birth==1986-19  | year_of_birth==1986-20 ///
| year_of_birth==1990-19  | year_of_birth==1990-20 ///
| year_of_birth==1994-19  | year_of_birth==1994-20 ///
| year_of_birth==1998-19  | year_of_birth==1998-20 ///
| year_of_birth==2002-19  | year_of_birth==2002-20 ///
| year_of_birth==2006-19  | year_of_birth==2006-20 ///
| year_of_birth==2010-19  | year_of_birth==2010-20 ///
| year_of_birth==2014-19  | year_of_birth==2014-20 ///
| year_of_birth==2018-19  | year_of_birth==2018-20 ///
| year_of_birth==1970-19 | year_of_birth==1970-20 ///
| year_of_birth==1966-19  | year_of_birth==1966-20 ///
| year_of_birth==1962-19  | year_of_birth==1962-20 ///
| year_of_birth==1958-19  | year_of_birth==1958-20 ///
| year_of_birth==1954-19  | year_of_birth==1954-20 ///
| year_of_birth==1950-19  | year_of_birth==1950-20 | year_of_birth==1946-19  | year_of_birth==1946-20   ///
| year_of_birth==1942-19  | year_of_birth==1942-20 | year_of_birth==1938-19  | year_of_birth==1938-20 ///
| year_of_birth==1934-19  | year_of_birth==1934-20 | year_of_birth==1930-19  | year_of_birth==1930-20 ///
| year_of_birth==1926-19  | year_of_birth==1926-20 | year_of_birth==1922-19  | year_of_birth==1922-20 ///
| year_of_birth==1918-19  | year_of_birth==1918-20 | year_of_birth==1914-19  | year_of_birth==1914-20 ///
| year_of_birth==1910-19  | year_of_birth==1910-20 | year_of_birth==1906-19  | year_of_birth==1906-20 ///
| year_of_birth==1902-19  | year_of_birth==1902-20 | year_of_birth==1898-19  | year_of_birth==1898-20 ///
| year_of_birth==1894-19  | year_of_birth==1894-20 | year_of_birth==1890-19  | year_of_birth==1890-20 ///
| year_of_birth==1886-19  | year_of_birth==1886-20 | year_of_birth==1882-19  | year_of_birth==1882-20 


* removing the states that reduced voting rights before 1972: Kentucky, Georgia, Alaska and Hawaii.
drop if state_code==21 | state_code==13 | state_code==2 | state_code==15
drop if elecyear<1956

gen treatment=0 
replace treatment=1 if year_of_birth==1978-19  ///
| year_of_birth==1982-19   ///
| year_of_birth==1986-19   ///
| year_of_birth==1990-19   ///
| year_of_birth==1994-19   ///
| year_of_birth==1998-19   ///
| year_of_birth==1974-19 ///
| year_of_birth==2002-19 ///
| year_of_birth==2006-19 ///
| year_of_birth==2010-19 ///
| year_of_birth==2014-19 ///
| year_of_birth==2018-19 



gen count=.
forvalues x=1/30 {
replace count=`x' if midterm_count==`x' |  pres_count==`x'
}
ta count,gen(cn)

* we remove women born 21 years before female voting rights were adopted and afro-americans born more than 21 years before 1965
drop if female==1 & year_of_birth<1920-21 
drop if race==2 & year_of_birth<1965-21


foreach var in treatment  age agesq   white  female    edu state_code cn1 cn2 cn3 cn4 cn5 cn6 cn7 cn8 cn9 cn10 cn11 cn12 cn13 cn14 cn15 cn16 cn17 cn18 cn19 college {
	
gen interact_`var'=presidential*`var'

}

*********************
*Table 3 starts here*
*********************

** Necessary controls: 
regr voted treatment interact_treatment presidential  cn2-cn15 interact_cn2-interact_cn15  age  agesq interact_age   interact_agesq  i.edu i.interact_edu   if  count>=2, cluster(state_code)
outreg2 using "Tables/MT.tex", addtext(Necessary Controls, Yes, Necessary Controls interacted, Yes, Additional Controls, No, Additional Controls Interacted, No, State dummies, No, State dummies interacted, No, Election pair fixed effects, Yes, Election pair interacted, Yes) keep(treatment interact_treatment) nocons nor2 replace

** All controls
regr voted treatment interact_treatment presidential  cn2-cn15 interact_cn2-interact_cn15 age  agesq    white   female  interact_age   interact_agesq   interact_white   interact_female   i.edu i.interact_edu     if  count>=2, cluster(state_code) 
outreg2 using "Tables/MT.tex", addtext(Necessary Controls, Yes, Necessary Controls interacted, Yes, Additional Controls, Yes, Additional Controls Interacted, Yes, State dummies, No, State dummies interacted, No, Election pair fixed effects, Yes, Election pair interacted, Yes) keep(treatment interact_treatment) nocons nor2 append


** All controls and state code
regr voted treatment interact_treatment presidential i.interact_state_code  cn2-cn15 interact_cn2-interact_cn15 age interact_age agesq  interact_agesq  white interact_white  female interact_female i.state_code  i.edu i.interact_edu     if  count>=2, cluster(state_code)
outreg2 using "Tables/MT.tex", addtext(Necessary Controls, Yes, Necessary Controls interacted, Yes, Additional Controls, Yes, Additional Controls Interacted, Yes, State dummies, Yes, State dummies interacted, Yes, Election pair fixed effects, Yes, Election pair interacted, Yes) keep(treatment interact_treatment) nocons nor2 append

*********************
*Table 3 ends here*
*********************


***********************
** Code for Table C1 ***
***********************

** flipside of Table 3: you are suddenly eligible in a presidential: 
clear all
use Data/anes_cumulative.dta, clear

gen year_of_birth=elecyear-age


keep if year_of_birth==1976-19 | year_of_birth==1976-20 ///
| year_of_birth==1980-19 | year_of_birth==1980-20 ///
| year_of_birth==1984-19  | year_of_birth==1982-20 ///
| year_of_birth==1988-19  | year_of_birth==1988-20 ///
| year_of_birth==1992-19  | year_of_birth==1992-20 ///
| year_of_birth==1996-19  | year_of_birth==1996-20 ///
| year_of_birth==1968-19  | year_of_birth==1968-20 ///
| year_of_birth==1964-19  | year_of_birth==1964-20 ///
| year_of_birth==1960-19  | year_of_birth==1960-20 ///
| year_of_birth==1956-19  | year_of_birth==1956-20 ///
| year_of_birth==1952-19  | year_of_birth==1952-20 ///
| year_of_birth==1948-19  | year_of_birth==1948-20 ///
| year_of_birth==1944-19  | year_of_birth==1944-20 /// 
| year_of_birth==1940-19  | year_of_birth==1940-20 /// 
| year_of_birth==1936-19  | year_of_birth==1936-20 /// 
| year_of_birth==1932-19  | year_of_birth==1932-20 /// 
| year_of_birth==1928-19  | year_of_birth==1928-20 /// 
| year_of_birth==1924-19  | year_of_birth==1924-20 ///
| year_of_birth==1920-19  | year_of_birth==1920-20 ///
| year_of_birth==2000-19  | year_of_birth==2000-20 ///
| year_of_birth==2004-19  | year_of_birth==2004-20 ///
| year_of_birth==2008-19  | year_of_birth==2008-20 ///
| year_of_birth==2012-19  | year_of_birth==2012-20 ///
| year_of_birth==2016-19  | year_of_birth==2016-20  | year_of_birth==1972-19  | year_of_birth==1972-20 ///
| year_of_birth==1916-19  | year_of_birth==1916-20 ///
| year_of_birth==1912-19  | year_of_birth==1912-20 ///
| year_of_birth==1908-19  | year_of_birth==1908-20 ///
| year_of_birth==1904-19  | year_of_birth==1904-20 ///
| year_of_birth==1900-19  | year_of_birth==1900-20 ///
| year_of_birth==1896-19  | year_of_birth==1896-20 ///
| year_of_birth==1892-19  | year_of_birth==1892-20 ///
| year_of_birth==1888-19  | year_of_birth==1888-20 ///
| year_of_birth==1884-19  | year_of_birth==1884-20 ///
| year_of_birth==1880-19  | year_of_birth==1880-20 


drop if state_code==21 | state_code==13 | state_code==2 | state_code==15
drop if elecyear<1956

gen treatment=0 
replace treatment=1 if year_of_birth==1976-19  ///
| year_of_birth==1980-19   ///
| year_of_birth==1984-19   ///
| year_of_birth==1988-19   ///
| year_of_birth==1992-19   ///
| year_of_birth==1996-19   ///
| year_of_birth==2000-19   | year_of_birth==2004-19  | year_of_birth==2008-19 ///
| year_of_birth==2012-19   | year_of_birth==2016-19 | year_of_birth==1972-19  | year_of_birth==1972-20 



gen elecyear_state=elecyear+state_code


gen count=.
forvalues x=1/20 {
replace count=`x' if midterm_count==`x' |  pres_count==`x'
}
ta count,gen(cn)

tab treatment year_of_birth 


drop if female==1 & year_of_birth<1920-21 
drop if race==2 & year_of_birth<1965-21

gen presidential_treat=treatment*presidential

foreach var in treatment  age agesq   white  female    edu state_code cn1 cn2 cn3 cn4 cn5 cn6 cn7 cn8 cn9 cn10 cn11 cn12 cn13 cn14 cn15 cn16 cn17 cn18  college {
	
gen interact_`var'=presidential*`var'

}

*********************
*Table C1 starts here*
*********************

** Necessary controls:  
regr voted treatment interact_treatment presidential  cn2-cn15 interact_cn2-interact_cn15  age  agesq interact_age   interact_agesq  i.edu i.interact_edu   if  count>=2, cluster(state_code)
outreg2 using "Tables/Pres.tex", addtext(Necessary Controls, Yes, Necessary Controls interacted, Yes, Additional Controls, No, Additional Controls Interacted, No, State dummies, No, State dummies interacted, No, Election pair fixed effects, Yes, Election pair interacted, Yes) keep(treatment interact_treatment) nocons nor2 replace

** All controls
regr voted treatment interact_treatment presidential  cn2-cn15 interact_cn2-interact_cn15 age  agesq    white   female  interact_age   interact_agesq   interact_white   interact_female   i.edu i.interact_edu     if  count>=2, cluster(state_code) 
outreg2 using "Tables/Pres.tex", addtext(Necessary Controls, Yes, Necessary Controls interacted, Yes, Additional Controls, Yes, Additional Controls Interacted, Yes, State dummies, No, State dummies interacted, No, Election pair fixed effects, Yes, Election pair interacted, Yes) keep(treatment interact_treatment) nocons nor2 append

** All controls and state code
regr voted treatment interact_treatment presidential i.interact_state_code  cn2-cn15 interact_cn2-interact_cn15 age interact_age agesq  interact_agesq  white interact_white  female interact_female i.state_code  i.edu i.interact_edu     if  count>=2, cluster(state_code)
outreg2 using "Tables/Pres.tex", addtext(Necessary Controls, Yes, Necessary Controls interacted, Yes, Additional Controls, Yes, Additional Controls Interacted, Yes, State dummies, Yes, State dummies interacted, Yes, Election pair fixed effects, Yes, Election pair interacted, Yes) keep(treatment interact_treatment) nocons nor2 append

*********************
*Table C1 ends here*
*********************


clear all


**********************************************
** Code for Table C2, column 1, (model 1) ***
**********************************************

************ Placebo MT (MODEL 1): 

clear all
set matsize 11000
use Data/anes_cumulative.dta, clear


 
gen year_of_birth=elecyear-age

keep if year_of_birth==1974-19 | year_of_birth==1974-18 | ///
year_of_birth==1978-19 | year_of_birth==1978-18 | ///
year_of_birth==1982-19 | year_of_birth==1982-18 | ///
year_of_birth==1986-19 | year_of_birth==1986-18  | ///
year_of_birth==1990-19 | year_of_birth==1990-18  | ///
year_of_birth==1994-19 | year_of_birth==1994-18 | ///
year_of_birth==1998-19 | year_of_birth==1998-18 | ///
year_of_birth==2002-19 | year_of_birth==2002-18 | ///
year_of_birth==2006-19 | year_of_birth==2006-18 | ///
year_of_birth==2010-19 | year_of_birth==2010-18 | ///
year_of_birth==2014-19 | year_of_birth==2014-18 | ///
year_of_birth==2018-19 | year_of_birth==2018-18 


gen count=.
forvalues x=1/30 {
replace count=`x' if midterm_count==`x' |  pres_count==`x'
}
ta count,gen(cn)

gen treatment=1 if year_of_birth==1974-19 | ///
year_of_birth==1978-19   | ///
year_of_birth==1982-19  | ///
year_of_birth==1986-19 |  ///
year_of_birth==1990-19 |  ///
year_of_birth==1994-19 | ///
year_of_birth==1998-19 | ///
year_of_birth==2002-19 |  ///
year_of_birth==2006-19 | ///
year_of_birth==2010-19 |  ///
year_of_birth==2014-19 |  ///
year_of_birth==2018-19 
replace treatment=0 if treatment!=1

foreach var in treatment  age agesq   white  female    edu state_code cn1 cn2 cn3 cn4 cn5 cn6 cn7 cn8 cn9 cn10 cn11 cn12 college {
	
gen interact_`var'=presidential*`var'

}


drop if female==1 & year_of_birth<1920-21 
drop if race==2 & year_of_birth<1965-21
drop if state_code==21 | state_code==13 | state_code==2  | state_code==15

********************************************
*Table C2 column 1 (model 1) starts here*
********************************************

regr voted treatment interact_treatment presidential  cn2-cn8 interact_cn2-interact_cn8 age  agesq    white   female  interact_age   interact_agesq   interact_white   interact_female   i.edu i.interact_edu     if  count>=2, cluster(state_code)
outreg2 using "Tables/placebo.tex", addtext(Necessary Controls, Yes, Necessary Controls interacted, Yes, Additional Controls, Yes, Additional Controls Interacted, Yes, State dummies, Yes, State dummies interacted, Yes, Election pair fixed effects, Yes, Election pair interacted, Yes) keep(treatment interact_treatment) nocons nor2 replace

********************************************
*Table C2 column 1 (model 1) ends here*
********************************************


**********************************************
** Code for Table C2, column 2, (model 2) ***
**********************************************


*** Placebo presidential (MODEL 2): 

clear all
set matsize 11000
use Data/anes_cumulative.dta, clear
 
gen year_of_birth=elecyear-age

keep if year_of_birth==1972-19 | year_of_birth==1972-18 | ///
year_of_birth==1976-19 | year_of_birth==1976-18 | ///
year_of_birth==1980-19 | year_of_birth==1980-18 | ///
year_of_birth==1984-19 | year_of_birth==1984-18  | ///
year_of_birth==1988-19 | year_of_birth==1988-18  | ///
year_of_birth==1992-19 | year_of_birth==1992-18 | ///
year_of_birth==1996-19 | year_of_birth==1996-18 | ///
year_of_birth==2000-19 | year_of_birth==2000-18 | ///
year_of_birth==2004-19 | year_of_birth==2004-18 | ///
year_of_birth==2008-19 | year_of_birth==2008-18 | ///
year_of_birth==2012-19 | year_of_birth==2012-18 | ///
year_of_birth==2016-19 | year_of_birth==2016-18 


gen count=.
forvalues x=1/30 {
replace count=`x' if midterm_count==`x' |  pres_count==`x'
}
ta count,gen(cn)

gen treatment=1 if year_of_birth==1972-19 | ///
year_of_birth==1976-19   | ///
year_of_birth==1980-19  | ///
year_of_birth==1984-19 |  ///
year_of_birth==1988-19 |  ///
year_of_birth==1992-19 | ///
year_of_birth==1996-19 | ///
year_of_birth==2000-19 |  ///
year_of_birth==2004-19 | ///
year_of_birth==2008-19 |  ///
year_of_birth==2012-19 |  ///
year_of_birth==2016-19 
replace treatment=0 if treatment!=1

foreach var in treatment  age agesq   white  female    edu state_code cn1 cn2 cn3 cn4 cn5 cn6 cn7 cn8 cn9 cn10 cn11 cn12 college {
	
gen interact_`var'=presidential*`var'

}


drop if female==1 & year_of_birth<1920-21 
drop if race==2 & year_of_birth<1965-21
drop if state_code==21 | state_code==13 | state_code==2 | state_code==15

********************************************
*Table C2 column 2 (model 2) starts here*
********************************************

regr voted treatment interact_treatment presidential  cn2-cn12 interact_cn2-interact_cn12 age  agesq    white   female  interact_age   interact_agesq   interact_white   interact_female   i.edu i.interact_edu     if  count>=2, cluster(state_code)
outreg2 using "Tables/placebo.tex", addtext(Necessary Controls, Yes, Necessary Controls interacted, Yes, Additional Controls, Yes, Additional Controls Interacted, Yes, State dummies, Yes, State dummies interacted, Yes, Election pair fixed effects, Yes, Election pair interacted, Yes) keep(treatment interact_treatment) nocons nor2 append

********************************************
*Table C2 column 2 (model 2) ends here*
********************************************

**********************************************
** Code for Table C2, column 3, (model 3) ***
**********************************************

** placebo MT - (model 3): 

clear all
set matsize 11000
use Data/anes_cumulative.dta, clear
 
gen year_of_birth=elecyear-age

keep if year_of_birth==1970-21 | year_of_birth==1970-22 | ///
year_of_birth==1966-21 | year_of_birth==1966-22 | ///
year_of_birth==1962-21 | year_of_birth==1962-22 | ///
year_of_birth==1958-21 | year_of_birth==1958-22  | ///
year_of_birth==1954-21 | year_of_birth==1954-22  | ///
year_of_birth==1950-21 | year_of_birth==1950-22 | ///
year_of_birth==1946-21 | year_of_birth==1946-22 | ///
year_of_birth==1942-21 | year_of_birth==1942-22 | ///
year_of_birth==1938-21 | year_of_birth==1938-22 | ///
year_of_birth==1934-21 | year_of_birth==1934-22 | ///
year_of_birth==1930-21 | year_of_birth==1930-22 | ///
year_of_birth==1926-21 | year_of_birth==1926-22  | ///
year_of_birth==1922-21 | year_of_birth==1922-22  | ///
year_of_birth==1918-21 | year_of_birth==1918-22  | ///
year_of_birth==1914-21 | year_of_birth==1914-22  | ///
year_of_birth==1910-21 | year_of_birth==1910-22  | ///
year_of_birth==1906-21 | year_of_birth==1906-22  

gen count=.
forvalues x=1/30 {
replace count=`x' if midterm_count==`x' |  pres_count==`x'
}
ta count,gen(cn)



gen treatment=1 if  year_of_birth==1970-21 | ///
year_of_birth==1966-21 | ///
year_of_birth==1962-21  | ///
year_of_birth==1958-21 | ///
year_of_birth==1954-21 | ///
year_of_birth==1950-21 | ///
year_of_birth==1946-21 | ///
year_of_birth==1942-21 | ///
year_of_birth==1938-21 | ///
year_of_birth==1934-21 | ///
year_of_birth==1930-21 | ///
year_of_birth==1926-21 | ///
year_of_birth==1922-21 | ///
year_of_birth==1918-21 | ///
year_of_birth==1914-21 | ///
year_of_birth==1910-21 | ///
year_of_birth==1906-21 


replace treatment=0 if treatment!=1

foreach var in treatment  age agesq   white  female    edu state_code cn1 cn2 cn3 cn4 cn5 cn6 cn7 cn8 cn9 cn10 cn11 cn12 cn13 cn14 cn15 college {
	
gen interact_`var'=presidential*`var'

}

drop if female==1 & year_of_birth<1920-21 
drop if race==2 & year_of_birth<1965-21
drop if state_code==21 | state_code==13 | state_code==2 | state_code==15
drop if elecyear<1956

********************************************
*Table C2 column 3 (model 3) starts here*
********************************************

regr voted treatment interact_treatment presidential  cn2-cn15 interact_cn2-interact_cn15 age  agesq    white   female  interact_age   interact_agesq   interact_white   interact_female   i.edu i.interact_edu     if  count>=2, cluster(state_code)
outreg2 using "Tables/placebo.tex", addtext(Necessary Controls, Yes, Necessary Controls interacted, Yes, Additional Controls, Yes, Additional Controls Interacted, Yes, State dummies, Yes, State dummies interacted, Yes, Election pair fixed effects, Yes, Election pair interacted, Yes) keep(treatment interact_treatment) nocons nor2 append

********************************************
*Table C2 column 3 (model 3) ends here*
********************************************

**********************************************
** Code for Table C2, column 4, (model 4) ***
**********************************************

** placebo Presidendial - model 4: 
clear all
set matsize 11000
use Data/anes_cumulative.dta, clear
 
gen year_of_birth=elecyear-age

keep if year_of_birth==1972-21 | year_of_birth==1972-22 | ///
year_of_birth==1968-21 | year_of_birth==1968-22 | ///
year_of_birth==1964-21 | year_of_birth==1964-22 | ///
year_of_birth==1960-21 | year_of_birth==1960-22  | ///
year_of_birth==1956-21 | year_of_birth==1956-22  | ///
year_of_birth==1952-21 | year_of_birth==1952-22 | ///
year_of_birth==1948-21 | year_of_birth==1948-22 | ///
year_of_birth==1944-21 | year_of_birth==1944-22 | ///
year_of_birth==1940-21 | year_of_birth==1940-22 | ///
year_of_birth==1936-21 | year_of_birth==1936-22 | ///
year_of_birth==1932-21 | year_of_birth==1932-22 | ///
year_of_birth==1928-21 | year_of_birth==1928-22  | ///
year_of_birth==1924-21 | year_of_birth==1924-22  | ///
year_of_birth==1920-21 | year_of_birth==1920-22  | ///
year_of_birth==1916-21 | year_of_birth==1916-22  | ///
year_of_birth==1912-21 | year_of_birth==1912-22  | ///
year_of_birth==1908-21 | year_of_birth==1908-22  

gen count=.
forvalues x=1/30 {
replace count=`x' if midterm_count==`x' |  pres_count==`x'
}
ta count,gen(cn)


gen treatment=1 if  year_of_birth==1972-21 | ///
year_of_birth==1968-21 | ///
year_of_birth==1964-21  | ///
year_of_birth==1960-21 | ///
year_of_birth==1956-21 | ///
year_of_birth==1952-21 | ///
year_of_birth==1948-21 | ///
year_of_birth==1944-21 | ///
year_of_birth==1940-21 | ///
year_of_birth==1936-21 | ///
year_of_birth==1932-21 | ///
year_of_birth==1928-21 | ///
year_of_birth==1924-21 | ///
year_of_birth==1920-21 | ///
year_of_birth==1916-21 | ///
year_of_birth==1912-21 | ///
year_of_birth==1908-21 


replace treatment=0 if treatment!=1

foreach var in treatment  age agesq   white  female    edu state_code cn1 cn2 cn3 cn4 cn5 cn6 cn7 cn8 cn9 cn10 cn11 cn12 cn13 cn14 cn15 college {
	
gen interact_`var'=presidential*`var'

}

drop if female==1 & year_of_birth<1920-21 
drop if race==2 & year_of_birth<1965-21
drop if state_code==21 | state_code==13 | state_code==2 | state_code==15
drop if elecyear<1956

********************************************
*Table C2 column 4 (model 4) ends here*
********************************************

regr voted treatment interact_treatment presidential  cn2-cn15 interact_cn2-interact_cn15 age  agesq    white   female  interact_age   interact_agesq   interact_white   interact_female   i.edu i.interact_edu     if  count>=2, cluster(state_code)
outreg2 using "Tables/placebo.tex", addtext(Necessary Controls, Yes, Necessary Controls interacted, Yes, Additional Controls, Yes, Additional Controls Interacted, Yes, State dummies, Yes, State dummies interacted, Yes, Election pair fixed effects, Yes, Election pair interacted, Yes) keep(treatment interact_treatment) nocons nor2 append

********************************************
*Table C2 column 4 (model 4) ends here*
********************************************


* Create log file
log using psrm.log

